package cn.edu.scau.cmi.zhangjunjia.composite.safe;


import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class SafeComposite  extends SafeComponent{

	
	
	
	public SafeComposite(String name) {
		super(name);
	}
	
	private ArrayList<SafeComponent> organizationArrayList = new ArrayList<SafeComponent>();
	
	
	
	
	
	
	public void add(SafeComponent child){
		this.organizationArrayList.add(child);
	}
	
	
	
	public void remove(SafeComponent child){
		this.organizationArrayList.remove(child);
	}
	
	

	@Override
	public void display(int high) {
		for(int i=0;i<high;i++) {
			System.out.print("-");
			
		}
		System.out.println(name);
	
	
	for(SafeComponent child: organizationArrayList) {
		child.display(high+1);
	}

	}
	
	@Override
	public String output(int depth) {
		// TODO Auto-generated method stub
		String str = "";
		for(int i = 0; i < depth; i++) {
			//System.out.print('-');
			str += '-';
		}
		//System.out.println(name);
		str += name;
		str += '\n';
		
		for(SafeComponent child: organizationArrayList) {
			str += child.output(depth + 1);
		}
		return str;
	}
}